package com.lecture.springlecture.entity;

import lombok.Data;

/**
 * @author luyn
 * @version 1.0
 * @description
 * @date 2022/3/28 10:31
 */
@Data
public class ResultBody<T> {

    /*状态码*/
    private int code;

    /*是否成功*/
    private boolean success;

    /*承载数据*/
    private T data;

    /*返回消息*/
    private String msg;

    private ResultBody(int code, T data,String msg,boolean success) {
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.success = success;
    }

    public static <T> ResultBody<T> success(String msg) {
        return new ResultBody<>(ResultCode.SUCCESS.code, null,msg,true);
    }

    public static <T> ResultBody<T> fail(String msg) {
        return new ResultBody<>(ResultCode.FAILURE.code,  null,msg,false);
    }

    public static <T> ResultBody<T> data(T data) {
        return new ResultBody<>(ResultCode.SUCCESS.code,data,null,true);
    }
}
